#include "Player.hpp"
#include "../Game/Game.hpp"
#include "../Game/tools.hpp"

Player::Player(void) : Entity("Player")
{
	m_type = PLAYER;

	m_current_state = IDLE_DOWN;
	m_anims[WALK_UP] = m_anims[IDLE_UP] = (new Animation(RES_DIR"/img/entity/noob_walk_up.png", 4, 200));
	m_anims[WALK_LEFT] = m_anims[IDLE_LEFT] = (new Animation(RES_DIR"/img/entity/noob_walk_left.png", 4, 200));
	m_anims[WALK_RIGHT] = m_anims[IDLE_RIGHT] = (new Animation(RES_DIR"/img/entity/noob_walk_right.png", 4, 200));
	m_anims[WALK_DOWN] = m_anims[IDLE_DOWN] = (new Animation(RES_DIR"/img/entity/noob_walk_down.png", 4, 200));
	m_anims[WALK_UP]->sprite().setScale(1.5f,1.5f);
	m_anims[WALK_LEFT]->sprite().setScale(1.5f,1.5f);
	m_anims[WALK_RIGHT]->sprite().setScale(2.f,1.5f);
	m_anims[WALK_DOWN]->sprite().setScale(1.5f,1.5f);
	m_anims[IDLE_UP]->sprite().setScale(1.5f,1.5f);
	m_anims[IDLE_LEFT]->sprite().setScale(1.5f,1.5f);
	m_anims[IDLE_RIGHT]->sprite().setScale(1.5f,1.5f);
	m_anims[IDLE_DOWN]->sprite().setScale(1.5f,1.5f);


	m_x_pos = 0;
	m_y_pos = 50;
	m_hitbox.setSize(24, 24);
	m_anims[m_current_state]->play();
}

Player::~Player(){

}

void Player::Update(){
	m_vel_y = m_vel_x = 0;
	float vel = 2;
	const Input& inputs =  Game::Instance()->getInput();
	
	bool walking = false;
	if(inputs.isKeyDown(Input::Down_Arrow)){
		walking = true;
		m_vel_y = vel;
	}else if(inputs.isKeyDown(Input::Up_Arrow)){
		walking = true;
		m_vel_y = -vel;
	}else if(inputs.isKeyDown(Input::Right_Arrow)){
		walking = true;
		m_vel_x = vel;
	}else if(inputs.isKeyDown(Input::Left_Arrow)){
		walking = true;
		m_vel_x = -vel;
	}
	
	Entity::Update();

	if(walking)
	{
		m_anims[m_current_state]->play();
	}
	else
	{
		m_anims[m_current_state]->stop();
	}
}
